﻿using System;
using System.Collections.Generic;
using System.Text;
using Cn.Cellula.Biz.Port;
using Cn.Cellula.Model;
using Cn.Edwon.Web.Session;
using System.Web;
using System.Reflection;
using Cn.Cellula.Model.System;

namespace Cn.Cellula.Biz.Impl {
    class LogBiz:MyBizSupport,ILogBiz {
        #region ILogBiz 成员

        public void Info(string rContent, ISessActor rActor, HttpRequest rRequest) {
            TSysLogEO eo = new TSysLogEO();
            try {
                eo.TypeName = "消息";
                eo.Content = (String.IsNullOrEmpty(rContent)) ? "没有信息" : rContent;
                eo.LogDate = DateTime.Now;
                eo.Operator = (rActor == null) ? "guest" : rActor.LoginName;
                eo.FromIp = rRequest.UserHostAddress;
                eo.Url = rRequest.Url.ToString();
                base.Save<TSysLogEO>(eo);
            } catch (Exception ex) {
                log.Error("系统日志错误：" + ex.Message);
            }
        }

        public void Error(string rContent, ISessActor rActor, HttpRequest rRequest) {
            TSysLogEO eo = new TSysLogEO();
            try {
                eo.TypeName = "异常";
                eo.Content = (String.IsNullOrEmpty(rContent)) ? "没有信息" : rContent;
                eo.LogDate = DateTime.Now;
                eo.Operator = (rActor == null) ? "guest" : rActor.LoginName;
                eo.FromIp = rRequest.UserHostAddress;
                eo.Url = rRequest.Url.ToString();
                base.Save<TSysLogEO>(eo);
            } catch (Exception ex) {
                log.Error("系统日志错误：" + ex.Message);
            }
        }

        #endregion

        #region ILogBiz 成员


        public void LogUpdate(string rEOName, String rItemName, ISessActor rActor, HttpRequest rRequest) {
            Info("更新了" + rEOName + ":" + rItemName, rActor, rRequest);
        }

        public void LogDelete(string rEOName, int rCount, ISessActor rActor, HttpRequest rRequest) {
            Info("删除了" + rCount + "条" + rEOName, rActor, rRequest);
        }

        public void LogInsert(string rEOName, String rItemName, ISessActor rActor, HttpRequest rRequest) {
            Info("增加" + rEOName + ":" + rItemName, rActor, rRequest);
        }

        #endregion
    }
}
